package com.im.users;


import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;
import org.springframework.util.AntPathMatcher;

public class JWTUtils {

    private static String sign = "im-app";

    public static String createToken(String json) {
        return JWT.create().withClaim("userInfo", json).sign(Algorithm.HMAC256(sign));
    }

    public static Boolean checkToken(String token) {
        try {
            DecodedJWT verify = JWT.require(Algorithm.HMAC256(sign)).build().verify(token);
            return true;
        } catch (Exception e) {
        }
        return false;
    }

    public static void main(String[] args) {
//        String user = createToken("user");
//        System.out.println(user);
        String url = "user/info/{id}";

        String url2 = "user/info/10";
        String url3 = "user/info/101";
        String url4 = "user/info/1/1";

        // 以后路径的匹配都用这个
        AntPathMatcher antPathMatcher = new AntPathMatcher();
        System.out.println(antPathMatcher.match(url,url2));
        System.out.println(antPathMatcher.match(url,url3));
        System.out.println(antPathMatcher.match(url,url4));
    }
}
